#!/bin/sh

post_savefile_html()
{
cat <<'EOF'

<script>
$(function(){
  $('#post_keep_files').on('submit', function(e){
    e.preventDefault();
    var data = "app=firmware&action=post_keep_files&"+$(this).serialize();
    var url = '/index.cgi';
    Ha.common.ajax(url, 'json', data, 'post', 'ajax-fluid');
  });
});
</script>
EOF
cat <<EOF
<form class="pure-form" id="post_keep_files">
<table class="pure-table pure-table-bordered">
	<thead><tr><td>Type</td><td>File</td><td>选项</td></tr></thead>
	<tbody>
EOF
sysupgrade_str=`cat /etc/sysupgrade.conf`
file_checked=`grep -F ':/' /$DOCUMENT_ROOT/apps/*/upgradekeep.list`
files_changed=`opkg list-changed-conffiles | grep -vE "/etc/sysupgrade.conf" | awk {'print "other:"$0'}`
echo "$file_checked" | awk -F ":" {'print $2'} >/etc/sysupgrade.conf
for i in `echo "$file_checked" | cut -d ':' -f2`
do
files_changed="$(echo "$files_changed" | grep -v "${i}")"
done
str=$(cat <<EOF)
$file_checked
$files_changed
EOF
echo "$str" | tr ':' ' ' | while read type file def_set
do
cat <<EOF
<tr>
	<td>
		${type}
	</td>
	<td>
		${file}
	</td>
	<td>
		<input name="file_$(grep -Eo '^[a-z0-9]{6}' /proc/sys/kernel/random/uuid)" value="${file}" type="checkbox" `([ "${def_set}" = "checked" ] || echo "$sysupgrade_str" | grep -q "^${file}$")&& echo "checked"`/>
	</td>
</tr>
EOF
done

cat <<EOF
<tr>
	<td>
		操作
	</td>
	<td>
	</td>
	<td>
		<button class="pure-button">保存</button>
	</td>
</tr>
</table>
	</tbody>

						
					</form>
EOF
}